{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.10.1+cu113\n",
      "GPU: True\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "print(torch.__version__) # torch的版本\n",
    "print('GPU:',torch.cuda.is_available())#GPu 是否支持"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 梯度下降算法\n",
    "$f(x)=x^2 \\times Sin(x)$\n",
    "\n",
    "$x_{n+1} = x_{n} - r\\bigtriangledown x_{n}$\n",
    " //下次迭代=当前x-x所对应的导数值,r为学习速率【调节步长】"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "初始的b = 0, w = 0, error = 10092.94328176009\n",
      "正在运算....\n",
      "最总的迭代的结果: w = 3.0187701315543705,b = 15.981961391582464, error = 73.77676404834698\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "# y = wx + b【w=3,b=15】\n",
    "def computer_loss_error(b,w,points): ## 定义loss函数\n",
    "    total_error = 0\n",
    "    for i in range(0,len(points)):\n",
    "        x = points[i,0]\n",
    "        y = points[i,1]\n",
    "        total_error = total_error + ((w * x + b) - y) ** 2 #与真实值的误差平方和\n",
    "    return total_error / float(len(points)) #对总误差进行一个平均\n",
    "\n",
    "def step_gradient(b_n,w_n,points,learningRate):##定义梯度，以及迭代公式\n",
    "    b_gradient = 0\n",
    "    w_gradient = 0\n",
    "    N = float(len(points))\n",
    "    for i in range(0,len(points)):\n",
    "        x = points[i,0]\n",
    "        y = points[i,1]\n",
    "        b_gradient = b_gradient - (2/N) * (y-((w_n * x) + b_n)) # 因为有100个点，所以要平均下导数信息\n",
    "        w_gradient = w_gradient - (2/N) * x * (y-((w_n * x) + b_n))\n",
    "    new_b = b_n - (learningRate * b_gradient)\n",
    "    new_w = w_n - (learningRate * w_gradient)\n",
    "    return [new_b,new_w]\n",
    "\n",
    "def gradient_decent_runner(ponints,b_0,w_0,learningRate,Max_iter):\n",
    "    b = b_0\n",
    "    w = w_0\n",
    "    for i in range(Max_iter):\n",
    "        b,w = step_gradient(b,w,np.array(ponints),learningRate)\n",
    "    return [b,w]\n",
    "\n",
    "def main():\n",
    "    points = np.genfromtxt(\"data.csv\",delimiter=',')\n",
    "    learningRate = 0.001\n",
    "    b_start = 0\n",
    "    w_start = 0\n",
    "    Max_iter = 20000\n",
    "    print(\"初始的b = {0}, w = {1}, error = {2}\".format(b_start,w_start,computer_loss_error(b_start,w_start,points)))\n",
    "    print(\"正在运算....\")\n",
    "    [b,w] =gradient_decent_runner(points,b_start,w_start,learningRate,Max_iter)\n",
    "    print(\"最总的迭代的结果: w = {},b = {}, error = {}\".format(w,b,computer_loss_error(b,w,points)))\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torch import nn\n",
    "from torch.nn import functional as F\n",
    "from torch import optim\n",
    "\n",
    "import torchvision\n",
    "from matplotlib import pyplot as plt\n",
    "from utils import plot_image,plot_curve,one_hot\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 下载数据包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([512, 1, 28, 28]) torch.Size([512]) tensor(-0.4242) tensor(2.8215)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZQAAAELCAYAAAD+9XA2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAceElEQVR4nO3dfbBUxZnH8d+DIE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lMYwduxYrx7esTHf/sADD1QlpvZobm4u2BZuvZKvh2tHMTBCAQBEQUIBAERBQgEARNGh1lCuvfZar37QQQcVPPaZZ56pdDjoAMK1tvXr13v1fB9ramry2vbff3+vvnnz5rjBIYpw65JwbWHq1KlZuR7XUCZMmFCw7aabbvLqlVg3yWOEAgCIgoQCAIiiQ015feYznynYFk5dLFmypNLhoANYvHixV3/55Ze9+oknnpiVR40a5bUNGjTIq7/00ktxg0NFzJ0716vnLx2//PLLvbbp06dXJaa88FLgE044ISuHU1ozZsyoRkgZRigAgChIKACAKEgoAIAoGnoNZdiwYV793HPPLXhsuA3GunXrKhITgMY2ceJErz5mzJisHF6GG257Uo3LiufMmePV82so4VZBlb5MOMQIBQAQBQkFABBFQ095nXfeeV692N301q5dW+lw0AmEUwr5HRfMrNrhoAqK7TYcTj/1798/K+/JJcXhTun55w0vG85Pw9XiMuY8RigAgChIKACAKEgoAIAozDlX+sFmpR9cBfPnz/fq4WXDzz//fFbOX1onSdu3b69UWFXnnKvryft66zd74hOf+IRXnzVrVlYePXq01/bcc8959auuuiorP/rooxWIrt2WO+eGt31Y7dRb3wnXL6ZNm+bV85cYh8ItXfIGDBjg1cO/V8XOE95xskpa7TuMUAAAUZBQAABRkFAAAFE03PdQunfvnpXDa7VDd955Z1buSGsmqJ2tW7d69Ztvvjkr79ixw2t77bXXvPqbb75ZucBQFeFWJuH6Rf5vUvidpfDvVX49JjxvuE4yb968rFyPd41swQgFABAFCQUAEEVDXzaMBJcNo0xcNoxycdkwAKBySCgAgChIKACAKEgoAIAoSCgAgChIKACAKEgoAIAoSCgAgChIKACAKEgoAIAoSCgAgChIKACAKEgoAIAoSCgAgCjae8fGdZJWViIQlG1QrQMoAf2mPtF3UK5W+0677ocCAEAhTHkBAKIgoQAAoiChAACiIKEAAKIgoQAAoiChAACiIKEAAKIgoQAAoiChAACiIKEAAKIgoQAAoiChAACiIKEAAKIoO6GY2QozOyVeKB2TmTWZmTOz9t4qoMOi75SGvuOj35Sm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fltScOOeQQr/7UU09l5W3bthV9bNeuu38V4Y7HxfTp08erjx8/PitPnz695POgPoW7SRfbITbcamfixIkViQmVdfLJJ3v1/CW94dTUqlWrvHp+mv3ll1/22vr16+fV8+cKz/Paa6959S9/+csF483HF27ZwpQXAKAhkVAAAFGQUAAAUdTdGsrcuXO9+qWXXurVDz300JLP1a1bt1bLMeXXXiSpe/fuFXkeVE+vXr2ycrgOlr9bp+TfvmDSpEleG3dhbAzDhg3z6jNnziz5sd/85je9+sCBA7NyuGYSyn/lILz8fPv27V79sccey8qf/OQnC56zqanJqzc3NxeNITZGKACAKEgoAIAoSCgAgCjqbg3l9ddf9+pf+tKXvHr+1r3h907CLROqYePGjV79tttuq3oMiGvkyJFZeciQIUWPzc9tL1iwoGIxoXL2228/r55fQ2vLypUrvfqNN95Y8NhwW6b8Nil/+ctfij7P/Pnzs/J3vvOdgseF63hjx4716uEtFWJjhAIAiIKEAgCIwpxzpR9sVvrBFZK/Y96xxx7rtX31q1/16vnpilNPPdVr69IlTi69+OKLvfqsWbOinLc9nHNW9Sdth3roN8WEd+hctmxZVh48eLDXFm6J8YUvfCErN+BO08udc8NrHUQx1eg7I0aM8Or5LZtaicerhzsI53ejDi8bvvLKK736jBkzSo4x/3WJN998s2BM4d/zE0880as/88wzJT9nG1rtO4xQAABRkFAAAFGQUAAAUdTdZcNtWbduXVYO74BX7I544Tzp4Ycf7tXz287nLxttzUcffZSVX3311aLHov7svffeXv2WW27x6vl1k/C2B1dddZVXb8B1E7QhXCfJC9deL7nkkoLHvvPOO169PWsmxYTx5WOaM2eO1xZxzaQkjFAAAFGQUAAAUZBQAABRNNwaSrmWLl3q1T/1qU959c997nMlnyu/7XR4XtS/I444wquHW5DnPfzww179oYceqkhMqJ0PPvjAq//+97/36vnvloS3AC72Pb7wVgfhNj7F1l/HjRvn1adMmVLwOfMx5Y+rBUYoAIAoSCgAgCg6zZRX6Gtf+5pX79mzZ8mPvfrqq2OHgwrL70Sd37m1NflL0ydOnFipkFAnwqmncIfeyZMnZ+XwsvFiwjsrhrtRr1mzJiuH01hDhw716uGOyHn5Kfj333+/5PgqgREKACAKEgoAIAoSCgAgik6zhhJuJf3FL36x7HNt3759T8NBlV122WVZuampqeix06ZNy8rNzc2VCgl1Kryr4TXXXJOVn3vuOa/tF7/4hVcvdrfHQYMGefV8P2zrNiJ///vfs/L999/vtc2cOTMrs4YCAOgQSCgAgCg6zZTXt771La/et2/fss+1fPnyPYwGlRbehfG6664reGy4K+zUqVMrEBE6gnnz5nn1sJ/lL+8N2370ox959fwl6eecc47XFu7QkP/2/uuvv15yvNXGCAUAEAUJBQAQBQkFABCFtXW5mnewWekH15k///nPXv24444r+1z5y/9WrVpV9nlicc4VvsVcHahFvznzzDO9erjtRd6FF17o1e+7776KxFSHljvnhtc6iGIa+W9OB9dq32GEAgCIgoQCAIiChAIAiKLTfA8l/K5Be9ZQwq0O1q5dGyUmVM7q1asLtj377LNeffbs2ZUOB+gUGKEAAKIgoQAAoug0U17FpkBCmzZt8uoXXHCBV//444+jxITKeeGFF7x6ly58dgIqjf/LAABRkFAAAFGQUAAAUXSaNZQbbrjBq2/evNmr//CHP8zK8+fP99pYMwGAtjFCAQBEQUIBAERBQgEARNFptq/vyNi+HmVi+3qUi+3rAQCVQ0IBAERBQgEAREFCAQBEQUIBAERBQgEARNHerVfWSVpZiUBQtkG1DqAE9Jv6RN9BuVrtO+36HgoAAIUw5QUAiIKEAgCIgoQCAIiChAIAiIKEAgCIgoQCAIiChAIAiIKEAgCIgoQCAIji/wA+029HifHyHwAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 432x288 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "batch_size = 512 #一次处理512张\n",
    "## 训练集\n",
    "train_loader = torch.utils.data.DataLoader(\n",
    "    torchvision.datasets.MNIST('mnist_data', train=True, download=True,\n",
    "                               transform=torchvision.transforms.Compose([\n",
    "                                   torchvision.transforms.ToTensor(), #返回的是np格式，转换成Tensor\n",
    "                                   torchvision.transforms.Normalize(\n",
    "                                       (0.1307,), (0.3081,)) #标准化，使其在0附近均匀分布\n",
    "                               ])),\n",
    "    batch_size=batch_size, shuffle=True) #随机打散\n",
    "\n",
    "\n",
    "## 测试集\n",
    "\n",
    "test_loader = torch.utils.data.DataLoader(\n",
    "    torchvision.datasets.MNIST('mnist_data/',train=False,download=True,\n",
    "                                transform = torchvision.transforms.Compose([\n",
    "                                    torchvision.transforms.ToTensor(),\n",
    "                                    torchvision.transforms.Normalize(\n",
    "                                        (0.1307,),(0.3081,))\n",
    "                                ])),\n",
    "    batch_size = batch_size ,shuffle = False)\n",
    "\n",
    "x, y = next(iter(train_loader))\n",
    "print(x.shape, y.shape, x.min(), x.max())\n",
    "plot_image(x, y, 'image sample')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 搭建网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([512, 1, 28, 28]) torch.Size([512]) tensor(-0.4242) tensor(2.8215)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZQAAAELCAYAAAD+9XA2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAfgklEQVR4nO3deZRUxd3/8c/XUVAQlUURIWgUF+CnxiX6gBr3FXyMP+Xwc8NIfJQYxUhcQEURPeJu1OgxIo8LuAEqLueIW0SinohiYtzQiILKpsgmRgSkfn/cnmvVdXro7qmZ7h7er3M41Je6fW8NXfDtqrpd15xzAgCgodYrdwMAAM0DCQUAEAUJBQAQBQkFABAFCQUAEAUJBQAQRckJxczeM7MD4jWleTKzbczMmdn65W5LpaDvFIa+E6LfFKac/abkhOKc6+mcm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tuuwVx27Zt0/LixYujXANA+bRs2TItn3POOUHdyJEj8x67Nj169EjL7du3L7F1lYURCgAgChIKACCKqpvy6ty5c1oeP358yef55ptvgvjuu+9Oy9nbjwcNGhTENTU1aTk77XbcccfVeU4A1cmf5rr22msb5RodO3YM4j333DOI33zzzUa5bmyMUAAAUZBQAABRkFAAAFFU3RrKFVdckZZ32mmneo/94IMP0vKf//znoO6pp54K4i+++CLveZYtWxbEw4YNy3tsdk0FzVvXrl3TcnZn4uw6HSrTkUceGcT+OqgknXjiiQWf65JLLknLCxYsCOqOP/74ID7iiCPScnZn4mwbWEMBAKxTSCgAgChIKACAKKpuDaUY/nzmpEmTSj7Pxx9/nLfu22+/DeIbbrih5OugMixatCgtb7LJJvUee9RRR6XlrbfeOqh799134zYM0fhP2rz33nuDug4dOgTx6tWr8x6b/V7KrFmz0vLKlSuDuuyar7+G0lwwQgEAREFCAQBE0aynvEqVfbLa+eefn/fYxx57LIjnzJnTKG1C0xk+fHhazj6RE83Diy++mJazO4+//vrrQTx9+vS0nN1tuD6dOnUK4uytwT5/mlUKv/JQTRihAACiIKEAAKIgoQAAomANpQ79+vUL4u7du5epJQAaw+23356W/ScnStIZZ5wRxDNnziz4vP76a3a7p1//+td5X5ddM7n//vsLvmYlYYQCAIiChAIAiIKEAgCIourWUObNm1fwsaeeempafumll4K6pUuXBrG/DcKNN95Y8DXmz59f8LEAKoO/LVPbtm2DutmzZ5d8Xn9rlvrWTJorRigAgChIKACAKKpuyuvqq69Oy7179w7q/B1EJemYY45Jy9ldQgcPHhzEo0aNSsvZIXDWQw89lJZHjhxZf4MBVBz/KazZJ7JmtWrVKi3vtttuQd3QoUODuE+fPgW34Z133knL++23X8Gvq2SMUAAAUZBQAABRkFAAAFFU3RrKd999l5avu+66oC67huLz11MkaZdddgnin//853lfu3DhwiD2bznMPrER1W+99X78nGVmBR/rb+chSfvvv3/chqEsunbtmpanTp1a77HZrfB9U6ZMCeKBAwc2qF2ViBEKACAKEgoAIAoSCgAgiqpbQ/Fl5zNPO+20IL7nnnvyvraYNZP+/fsH8axZswpsIarRl19+mZazW/RssskmQbxmzZq0XN/8OarHpZdeGsQHHHBASefJPko4uy1+Q7Z4qVSMUAAAUZBQAABRVPWUl38LsbT2LRQKlR2qZncqRvP2/PPPp2V/ewxJ2meffZq6OWgE/nYq2e1TLrjggiBu0aJFweddsmRJWs5u77R48eK8r9tpp50KvkYxNt100yC+6KKL0vLFF18c1GWn4LL/vxaCEQoAIAoSCgAgChIKACCKql5D2XrrrYN4zJgxUc675ZZbBvFmm20WxP48KYDq429D72+l1FD+/xXZtdgJEyYEsb9WN3r06KCuKW5Bz25H5T8aRJKGDx9e9DkZoQAAoiChAACiIKEAAKKoujWU1q1bp+WbbropqMuudfiy27TsuOOOQdyxY8e0vMceewR1ffv2DeJx48YV1FZUp86dO6fldu3albElaE769euXN84+JqEc2/hkv5fCGgoAoGxIKACAKKpuyuvyyy9Py8cee2y9xy5atCgtn3vuuUHdgAEDgvi8887Le57sdZjyat5+9atfpeXu3buXsSVoLG+99VZavvLKK4O63/3ud3lft+GGGwbxxhtvXHIb/K8ftGnTJqhbsWJFEPtT/cXIbvfyww8/5D120KBBJV3DxwgFABAFCQUAEAUJBQAQRcWvofjbTEtSr169Cn7tH//4x7T89ttvB3WfffZZwxqGZsvvK9ktvbPb/aA6+VuzjxgxIqjLxr5DDjkkiM8666yS2+DfpnvqqacGddOmTQviU045paRrnH322UE8d+7cks5TKEYoAIAoSCgAgCismG9kmlmTf32zU6dOQTxnzpy8x3744YdBPGzYsLS81157BXVDhgwJ4vqeypbdjXTUqFF5jy0H55yt/ajyKUe/ieXll18O4uwTG/1vOK9atSqoO/nkk4N44sSJkVvXYNOdc3uWuxH1qea+08zV2XcYoQAAoiChAACiIKEAAKKo+NuGFyxYEMQPPPBAWj7ppJOCum7dugXxI488kpY32GCDgq/pP0lNkq6//vqCX4vmJbtedt999wVxhw4d0vL664f/nLIx0NwxQgEAREFCAQBEQUIBAERR8ZO8a9asC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7u5ytwU/ou+gFPSb0lXkFxvN7Fgza2lmbZV8seapSn1jUVnoOygF/SaOikwoks5Uct/4TEk/SPpdeZuDKkLfQSnoNxFU/JQXAKA6VOoIBQBQZUgoAIAoivpio5kxP1aBnHMN+XJUo6PfVKyFzrl83/iuCPSdilVn32GEAqy7Zpe7AahadfYdEgoAIAoSCgAgChIKACAKEgoAIIom374eiKV9+/ZpedKkSUHdZZeFD9R76aWXmqJJwDqNEQoAIAoSCgAgChIKACAK1lBQtVq1apWW991336Bu6NChQcwaCtD4GKEAAKIgoQAAoiChAACiqOo1lPPOOy+ITzzxxCDeY4898r52+vTpQfzoo4+m5dGjRwd1X3/9dalNRCP66quv0vI//vGPoG7vvfcO4i5duqTlL774onEbBqyjGKEAAKIgoQAAoqj4Ka+2bdsG8fvvv5+WO3ToENStt16YH2fOnJmW77zzzqBu9913D+JLLrkkLR933HFBXXYK7K677lpbs9EEVqxYkZaffvrpoG748OFB7N9iDKBxMEIBAERBQgEAREFCAQBEUXFrKDU1NUE8ZsyYIO7YsWNavuqqq4K6iRMnBvGnn36alr/55pt6r7vDDjuk5T59+gR1559/fhBPmDAhLS9evLje86JpfPTRR+VuArDOY4QCAIiChAIAiKLiprw233zzID7mmGPyHnv77bcH8YIFC0q+rj9lkp0+ufnmm0s+LyrDYYcdlpaZHmueWrduHcTLly9Py99//31QN27cuDqPk6SHH3447zV23HHHIN5nn32C2P/qgj89L0nbb7993vaedNJJQd3UqVPztqGSMUIBAERBQgEAREFCAQBEUXFrKEuXLg3i9957L4h33nnntNypU6egriFrKGjeOnfuXO4moIk559Jyy5Ytg7qBAwfmfd3gwYOjXN/M8rYn64UXXgjiIUOGBLG/XlzfecqNEQoAIAoSCgAgChIKACCKiltD+e6774J45MiRQTx+/Pi0PGnSpKCuV69eQTxv3ry4jSuAv90+27IATeeHH34I4i+//DItb7HFFk3dnKLWOjbYYIMgvvXWW4N4ypQpafndd99tULsaEyMUAEAUJBQAQBQVN+WVld1BePr06Wk5+9TF6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+Q9b+/evYO4R48eabldu3ZBXd++fdPytGnT1tLiOLhtGCXituEKceCBBwZx9pbz+nDbMACg2SGhAACiIKEAAKKo6u+hZI0aNSqIn3322bQ8fvz4oK6YreX9e8AladGiRWn5qKOOCuqaat0EQPMxd+7ceuv9/4MmTpwY1K1YsaJR2lQKRigAgChIKACAKJrVlFfWW2+9lZabaudfAChW//79Cz525cqVQVzMVz8aGyMUAEAUJBQAQBQkFABAFM16DQUAqsFrr71W7iZEwQgFABAFCQUAEAUJBQAQBWsoAFBmU6dODeJXX301iPfZZ5+0PGPGjCZpUykYoQAAoiChAACiYMoLAMosu53KfvvtV6aWNAwjFABAFCQUAEAUJBQAQBTFrqEslDS7MRqCkm1d7gYUgH5Tmeg7KFWdfccqaS99AED1YsoLABAFCQUAEAUJBQAQBQkFABAFCQUAEAUJBQAQBQkFABAFCQUAEAUJBQAQxf8H3DFCnlSmggIAAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 432x288 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 0 0.12625159323215485\n",
      "0 10 0.09760372340679169\n",
      "0 20 0.08658014237880707\n",
      "0 30 0.08233888447284698\n",
      "0 40 0.0769028514623642\n",
      "0 50 0.07238651812076569\n",
      "0 60 0.06741845607757568\n",
      "0 70 0.065525121986866\n",
      "0 80 0.06086692959070206\n",
      "0 90 0.060062624514102936\n",
      "0 100 0.05526856333017349\n",
      "0 110 0.0536922812461853\n",
      "1 0 0.05162475258111954\n",
      "1 10 0.05075077340006828\n",
      "1 20 0.047675203531980515\n",
      "1 30 0.04799049347639084\n",
      "1 40 0.043133217841386795\n",
      "1 50 0.04545358568429947\n",
      "1 60 0.04679827764630318\n",
      "1 70 0.04131340608000755\n",
      "1 80 0.04162602871656418\n",
      "1 90 0.041914500296115875\n",
      "1 100 0.04062296077609062\n",
      "1 110 0.040015291422605515\n",
      "2 0 0.041084159165620804\n",
      "2 10 0.03726635128259659\n",
      "2 20 0.036953069269657135\n",
      "2 30 0.036783505231142044\n",
      "2 40 0.036160312592983246\n",
      "2 50 0.03570713847875595\n",
      "2 60 0.03787250816822052\n",
      "2 70 0.03572765737771988\n",
      "2 80 0.035780955106019974\n",
      "2 90 0.03497128188610077\n",
      "2 100 0.03609266132116318\n",
      "2 110 0.032625336199998856\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEGCAYAAAB/+QKOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAp8klEQVR4nO3dd5iU9dX/8fdhKaIQVESlqBRRxAIiIhYsUQkSlGBvib1EjfFRk2DsqM8TTYyx/WxBxZJgiSYoKhYssQELolIVFQU0UmwgCgLn98e5JzO7zMICO3vP7nxe1zXXXWf27H3BnP12c3dEREQqa5B2ACIiUpyUIEREJC8lCBERyUsJQkRE8lKCEBGRvBqmHUBN2WSTTbx9+/ZphyEiUqeMHz9+vru3ynet3iSI9u3bU15ennYYIiJ1ipl9XNU1VTGJiEheShAiIpKXEoSIiOSlBCEiInkpQYiISF5KECIikpcShIiI5FXyCcIdLrwQpk5NOxIRkeJS8gni/fdh6FDo1g0mTUo7GhGR4lHyCWKbbeCtt+CHH+CZZ9KORkSkeJR8ggBo3x622grGjUs7EhGR4qEEkejVC8aOTTsKEZHioQSR6NULZs6E+fPTjkREpDgoQSS6dInthx+mG4eISLFQgki0axfb2bPTjUNEpFgoQSSUIEREKlKCSLRsCU2aKEGIiGQoQSTMoG1bJQgRkYyCJggz62dm081shpkNznN9bzObYGbLzOzwnPPdzewNM5tsZu+Y2VGFjDOjXTslCBGRjIIlCDMrA24FDgK6AseYWddKt30CnAj8rdL5xcAv3H17oB/wFzPbsFCxZrRrB3PmFPqniIjUDQ0L+Nm9gBnu/iGAmQ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8x2JRDUDeARokpxfLzmekVzvWASxjk6e7STgAbI9nWr834Gm2hARkbxKvYpJRESqoAQhIiJ5KUGIiEheShAiIpKXEoSIiOSlBCFSA8zs9WTb3syOTTsekZqgBCFSA9x9j2S3PbBGCSJnBK9IUVGCEKkBZpaZdfMPQJ9knv7/SSZb+6OZjUsmVzsjuX9fM/u3mY0ApqQWuMgq6C8XkZo1mFgHYQBAMgPv1+6+azLr5mtm9mxybw9gB49pr0WKjhKESGH1BXYys8w8Py2I+YeWAmOVHKSYKUGIFJYBv3L3URVOmu0LfJtGQCLVpTYIkZq1kFh6M2MU8MtkSmzMbJtkZl6RoqcShEjNegdYbmZvE2sH30j0bJqQTM88jxSXiBVZE5rNVURE8lIVk4iI5KUEISIieSlBiIhIXkoQIiKSlxKEiIjkpQQhIiJ5KUGIiEhe/x+QnruyU4LlygAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "x, y = next(iter(train_loader))\n",
    "print(x.shape, y.shape, x.min(), x.max())\n",
    "plot_image(x, y, 'image sample')\n",
    "\n",
    "\n",
    "\n",
    "class Net(nn.Module):\n",
    "\n",
    "    def __init__(self):\n",
    "        super(Net, self).__init__()\n",
    "\n",
    "        # xw+b\n",
    "        self.fc1 = nn.Linear(28*28, 256)\n",
    "        self.fc2 = nn.Linear(256, 64)\n",
    "        self.fc3 = nn.Linear(64, 10)\n",
    "\n",
    "    def forward(self, x):\n",
    "        # x: [b, 1, 28, 28]\n",
    "        # h1 = relu(xw1+b1)\n",
    "        x = F.relu(self.fc1(x))\n",
    "        # h2 = relu(h1w2+b2)\n",
    "        x = F.relu(self.fc2(x))\n",
    "        # h3 = h2w3+b3\n",
    "        x = self.fc3(x)\n",
    "\n",
    "        return x\n",
    "\n",
    "\n",
    "\n",
    "net = Net()\n",
    "# [w1, b1, w2, b2, w3, b3]\n",
    "### 自动优化\n",
    "optimizer = optim.SGD(net.parameters(), lr=0.01, momentum=0.9)\n",
    "\n",
    "\n",
    "### 计算误差函数\n",
    "train_loss = []\n",
    "\n",
    "for epoch in range(3):\n",
    "\n",
    "    for batch_idx, (x, y) in enumerate(train_loader):\n",
    "\n",
    "        # x: [b, 1, 28, 28], y: [512]\n",
    "        # [b, 1, 28, 28] => [b, 784]\n",
    "        x = x.view(x.size(0), 28*28)\n",
    "        # => [b, 10]\n",
    "        out = net(x)\n",
    "        # [b, 10]\n",
    "        y_onehot = one_hot(y)\n",
    "        # loss = mse(out, y_onehot)\n",
    "        loss = F.mse_loss(out, y_onehot)\n",
    "\n",
    "        optimizer.zero_grad()\n",
    "        loss.backward()\n",
    "        # w' = w - lr*grad\n",
    "        optimizer.step()\n",
    "\n",
    "        train_loss.append(loss.item())\n",
    "\n",
    "        if batch_idx % 10==0:\n",
    "            print(epoch, batch_idx, loss.item())\n",
    "plot_curve(train_loss)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 计算准确率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集的准确率为:88.28%\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZQAAAELCAYAAAD+9XA2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAYTElEQVR4nO3dfawV1bnH8d8CeRNTRYqKoiB4iyLlTaiUYsWK8iIoiAgX2oreK9pINVGhVuzVWr22NLFRK9A24arY2kZAg4IKaXjRqI0QRKHQBixvKbQcKcjhpQJn3T/2dpw1nr05e5+152Xz/SSTrIc1zDybM9kPa9acNcZaKwAAGqtJ0gkAAKoDBQUA4AUFBQDgBQUFAOAFBQU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EQoAwAsKCgDAi9Tf8irm9ddfLxoDcXrvvfec+PHHH3fiZcuWxZkOKuDYsWNOPH36dCcOL7ezevXqWHJKE0YoAAAvKCgAAC8oKAAAL0wpS2wbY1iPO4WstYVfDZgCXDeptdpa2zfpJIrh2kmteq8dRigAAC8oKAAALygoAAAvKCgAAC8oKAAALygoAAAvKCgAAC8oKAAALygoAAAvKCgAAC9KXb6+RtLWSiSCsnVMOoEG4LpJJ64dlKvea6ektbwAACiEW14AAC8oKAAALygoAAAvKCgAAC8oKAAALygoAAAvKCgAAC8oKAAALygoAAAv/h++EuktFFvobQAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 432x288 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "total_correct = 0\n",
    "for x,y in test_loader:\n",
    "    x  = x.view(x.size(0), 28*28)\n",
    "    out = net(x)\n",
    "    # out: [b, 10] => pred: [b]\n",
    "    pred = out.argmax(dim=1)\n",
    "    correct = pred.eq(y).sum().float().item()\n",
    "    total_correct += correct\n",
    "\n",
    "total_num = len(test_loader.dataset)\n",
    "acc = total_correct / total_num\n",
    "print('测试集的准确率为:'+ str(acc*100) + '%')\n",
    "\n",
    "x, y = next(iter(test_loader))\n",
    "out = net(x.view(x.size(0), 28*28))\n",
    "pred = out.argmax(dim=1)\n",
    "plot_image(x, pred, 'test')"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "4ce0e62306dd6a5716965d4519ada776f947e6dfc145b604b11307c10277ef29"
  },
  "kernelspec": {
   "display_name": "Python 3.9.6 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
